package com.example.springbootfoodsafety.serviceimpl;

import com.example.springbootfoodsafety.dao.UserDao;
import com.example.springbootfoodsafety.entity.User;
import com.example.springbootfoodsafety.po.Article;
import com.example.springbootfoodsafety.po.Friends;
import com.example.springbootfoodsafety.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao dao;
    @Override
    public List<Article> getUserArticle(Integer id) {
        return dao.getUserArticle(id);
    }

    @Override
    public boolean modifyUser(User user) {
        return dao.modifyUser(user);
    }

    @Override
    public List<User> getUserFriends(Integer id) {
        List<Friends> list=dao.getUserFriends(id);
        int arr[]=new int[list.size()];
        int count=0;
        for(Friends i:list)
        {
            arr[count++]=i.getFriendId();
        }
        List<User> friends=new ArrayList<>();
        for(int i=0;i<arr.length;i++)
        {
            friends.add(dao.getAllFriendsUser(arr[i]));
        }
        System.out.println(friends);
        return friends;
    }

    @Override
    public boolean addFriends(Integer masterId, Integer friendId) {
        return dao.addFriends(masterId,friendId);
    }
}
